import { templateToDom } from "./compile";

const domPool = [];

export function createApp(options) {
    let components;
    for (let option in options) {
        switch (option) {
            case 'components':
                initComponents(options[option]);
                break;
            default:
                break;
        }
    }
    return {
        mount
    }
}

function mount(el) {
    el = document.querySelector(el);
    if (domPool) {
        for (let dom in domPool) {
            el.appendChild(domPool[dom]);
        }
    }
}

function initComponents(components) {
    for (let component in components) {
        let [template, state] = components[component]();
        let html = templateToDom(template, state);
        domPool.push(html);
    }
}
